package game;

import java.util.LinkedList;

import GUI.gameWinOld.ScorePanel;


public class ClassicMatchResults extends MatchResults{
	private LinkedList<Player> players;
	private int[] results;
	private int playerCount;
	private Player lastWinner;
	private int spree;
	private final int matchNum;

	public ClassicMatchResults(int match) {
		playerCount = GameSettingsOld.getInstance().playerCount;
		players = GameSettingsOld.getInstance().players;
		results = new int[playerCount];
		for (int i = 0; i < playerCount; i++) {
			results[i]=0;
		}
		lastWinner = null;
		spree=0;
		roundNum=1;
		matchNum=match;
	}
	
	public void addRound(Player winner, int[] points, ScorePanel scorePanel) {
		for(int i = 0;i<playerCount;i++)
			results[i]+=points[i];
		if(lastWinner==winner)
			spree++;
		else
			spree = 1;
		results[players.indexOf(winner)]+=spree*50;
		lastWinner = winner;
		roundNum++;
		updateScoreboard(scorePanel);
	}
	
	private void updateScoreboard(ScorePanel scorePanel) {
		String[] row = new String[playerCount*2];
		for(int i = 0; i<playerCount;i++) {
			if(players.get(i)==lastWinner)
				row[i*2]="*";
			row[i*2+1]=Integer.toString(results[i]);
		}
		scorePanel.addResult(matchNum, row);
	}
	
}
